import type { Component } from 'vue'
import type { CustomComponentMeta } from '@/types/schema'

class ComponentRegistry {
  private components = new Map<string, { component: Component; meta: CustomComponentMeta }>()

  register(name: string, component: Component, meta: CustomComponentMeta) {
    this.components.set(name, { component, meta })
  }

  get(name: string) {
    return this.components.get(name)
  }

  getAll() {
    return Array.from(this.components.values())
  }

  getNames() {
    return Array.from(this.components.keys())
  }
}

export const componentRegistry = new ComponentRegistry()
